package com.jxud.mapper;

import com.jxud.pojo.Emp;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface EmpMapper {
    /**
     * 查询总记录数
     *
     * @return
     */
    @Select("select count(*) from emp")
    public long count();

//    /**
//     * 分页查询获取数据
//     * @param    页数
//     * @param    每页展示多少
//     * @return
//     */
//    @Select("select * from emp limit #{start},#{pageSize} ")
//    public List<Emp> page(Integer start, Integer pageSize);

    //pagehelp 分页查询
//    @Select("select * from emp")
    public List<Emp> list(String name, Boolean gender, LocalDate begin, LocalDate end);

    //删除员工的mapper
    @Delete("delete  from emp where id = #{id}")
    void delete(Integer id);

    //添加员工的mapper
    @Insert("INSERT INTO emp (name, position, hire_date, department_id, gender, phone, created_at, updated_at) " +
            "VALUES (#{name}, #{position}, #{hireDate}, #{departmentId}, #{gender}, #{phone}, #{createdAt}, #{updatedAt})")
    void add(Emp emp);

    @Select("select * from emp where id = #{id}")
    Emp getById(Integer id);

    //更新员工
    void update(Emp emp);

    //根据用户名和密码查登录
    @Select("select * from emp where name = #{name} and password = #{password}")
    Emp getByUsernameAndPassword(Emp emp);

    @Delete("delete from emp where department_id = #{id}")
    void deleteByDeptId(Integer id);
}
